<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link href="mstatic/css/bootstrap.min.css"  type="text/css" rel="stylesheet">
    <link rel="stylesheet" href="mstatic/css/font-awesome.min.css" />
    <link rel="stylesheet" href="mstatic/css/fullcalendar.css" /><!--页面特定插件风格-->
    <link rel="stylesheet" href="mstatic/css/ace.min.css" /><!--必要-->
    <link href="mstatic/css/index.css" type="text/css" rel="stylesheet">
    <title>通用事项</title>
</head>

<body>
<!--头部-->
<nav class="navbar navbar-default navbar-fixed-top  top" role="navigation">
    <div class="container-fluid">

        <div class="navbar-header" style=" width:100%;">
            <a class="navbar-brand" href="javascript:history.go(-1);" style=" width:100%;  padding-right:0px;">

                <span class="glyphicon glyphicon-arrow-left white" style="font-size:18px;"></span>
                <!--    <span class="glyphicon glyphicon-pause white" style="margin-left:2%;"></span>-->
                <span class="white" style="margin-left:10%;font-size:18px">通用事项</span>
                <span class="glyphicon glyphicon-user white" style="float:right;font-size:18px"></span>


            </a>


        </div>



    </div><!-- /.container-fluid -->
</nav>
  <!--主要内容开始-->
<div class="container" style="margin-top:70px;margin-left:2%;margin-right:2%">
    <div class="row">


        <div class="main-content">
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">


                        <div class="row">
                            <div class="col-sm-9">
                                <div class="space"></div>
                                <div id="calendar"></div>
                            </div>
                        </div>


                    </div>

                </div>
            </div><!--page-content  end-->

        </div><!--page-content  end-->



    </div><!--row  end-->
</div>
  <!--主要内容结束-->

{%include file="m.index.footer.tpl.php"%}
<!-- ./wrapper -->


<!--底部end-->
<script src="mstatic/js/jquery.min.js" type="text/javascript"></script>
<script src="mstatic/js/bootstrap.min.js"  type="text/javascript"></script>
<script src="mstatic/js/jquery-ui-1.10.3.custom.min.js"></script><!--点击删除-->
<script src="mstatic/js/fullcalendar.min.js"></script><!--必要 基本-->
<script src="mstatic/js/bootbox.min.js"></script><!--点击弹框-->
<script type="text/javascript">
$(function() {
    var calendar = $('#calendar').fullCalendar({
        buttonText: {
            prev: '<i class="glyphicon glyphicon-chevron-left"></i>',
            next: '<i class="glyphicon glyphicon-chevron-right"></i>'
        },
		header: {
			left: 'prev,next today',
			center: 'title',
			right: 'month,agendaWeek,agendaDay'
		},
		editable: true,
        droppable: true,
		dragOpacity: {
			agenda: .5,
			'':.6
		},
		eventDrop: function(event,dayDelta,minuteDelta,allDay,revertFunc) {
			$.post("index.php?a=event.dodrag",{id:event.id,daydiff:dayDelta,minudiff:minuteDelta,allday:allDay},function(msg){
				if(msg!=1){
					alert(msg);
					revertFunc();
				}
			});
    	},
		
		 eventResize: function(event,dayDelta,minuteDelta,revertFunc) {
			$.post("index.php?a=event.doresize",{id:event.id,daydiff:dayDelta,minudiff:minuteDelta},function(msg){
				if(msg!=1){
					alert(msg);
					revertFunc();
				}
			});
    	},
		
		
		selectable: true,
        selectHelper: true,
        select: function(start, end, allDay) {

            bootbox.prompt("录入内容", function (title) {
                if (title !== null) {
                    calendar.fullCalendar('renderEvent',
                        {
                            title: title,
                            start: start,
                            end: end,
                            allDay: allDay
                        },
                        true // make the event "stick"
                    );
                    var timestamp = Date.parse(start);
                    timestamp = timestamp / 1000;
                    $.post("index.php?a=event.doadd",{event:title,startdate:timestamp,enddate:end,isallday:allDay},function () {
                        alert("添加成功");
                    })
                }
            });
            calendar.fullCalendar('unselect');

        }
        ,
//		select: function( startDate, endDate, allDay, jsEvent, view ){
//			var start =$.fullCalendar.formatDate(startDate,'yyyy-MM-dd');
//			var end =$.fullCalendar.formatDate(endDate,'yyyy-MM-dd');
//			$.fancybox({
//				'type':'ajax',
//				'href':'index.php?a=event.add&date='+start+'&end='+end
//			});
//		},
		
		
		events: 'index.php?a=event.getjson',
		dayClick: function(date, allDay, jsEvent, view) {
			var selDate =$.fullCalendar.formatDate(date,'yyyy-MM-dd');
//			$.fancybox({
//				'type':'ajax',
//				'href':'index.php?a=event.add&date='+selDate
//			});
    	},
        eventClick: function(calEvent, jsEvent, view) {
            var form = $("<form action='index.php?a=event.doupdate' method='post' class='form-inline'><label>更改事件名称&nbsp;</label></form>");
            form.append("<input class='middle' autocomplete=off type=text name='event' value='" + calEvent.title + "' /> ");
            form.append("<input type=hidden name='id' value='" + calEvent.id + "' /> ");
            form.append("<button type='submit' class='btn btn-sm btn-success'><i class='icon-ok'></i> 保存</button>");

            var div = bootbox.dialog({
                message: form,

                buttons: {
                    "delete" : {
                        "label" : "<i class='icon-trash'></i>删除",
                        "className" : "btn-sm btn-danger",
                        "callback": function() {
                            calendar.fullCalendar('removeEvents' , function(ev){
                                $.post("index.php?a=event.dodel",{id:(calEvent.id)},function () {
                                    //alert("删除成功");
                                })
                                return (ev._id == calEvent._id);
                            })
                        }
                    } ,
                    "close" : {
                        "label" : "<i class='icon-remove'></i> 关闭",
                        "className" : "btn-sm"
                    }
                }

            });

            form.on('submit', function(){
                calEvent.title = form.find("input[type=text]").val();
                calendar.fullCalendar('updateEvent', calEvent);
                div.modal("hide");
                //return false;
            });


        }
	});
	
});
</script>

</body>
</html>

